package club.justwill.single.persistence.store;

import club.justwill.single.persistence.document.ProjectHits;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

/**
 * Created by luoyu on 2/23/16.
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class ProjectHitsStore extends MongoDbStore<ProjectHits> {
    public ProjectHits getById(Long projectId) {
        return mongoTemplate.findOne(Query.query(Criteria.where("projectId").is(projectId)),ProjectHits.class);
    }
    public void addHits(ProjectHits projectHits) {
        projectHits.setProjectHits(projectHits.getProjectHits()+1);
        mongoTemplate.save(projectHits);
    }
}
